﻿using STHPMS1.DAL.D_Core;
using System.Data;
using ServiceStack.OrmLite;
using STHPMS1.ICore.I_Entity.Stmpms1;
using STHPMS1.Common.C_Entity.Stmpms1;
using STHPMS1.ICore.I_DAL.Repository;
using System.Collections.Generic;
using System.Data.SqlClient;

namespace STHPMS1.DAL.D_Repository
{
    public class Dr_Repair_LarRepository : DalBase, IDr_Repair_LarRepository
    {
        /// <summary>
        /// 获取龟裂、重度纵向裂缝、重度横向裂缝的病害面积
        /// </summary>
        /// <param name="segid"></param>
        /// <returns></returns>
        public double GetASPArea(string segid)
        {
            IDbConnection conn = Adapter.OpenDbConnection();
            return conn.Scalar<double>("select isnull(sum(ALGCK_L*0.6+ALGCK_M*0.8+ALGCK_H*1+LGCK_H*1*0.2+TRSCK_H*1*0.2),0) as ALGCK_LMH "
                            +"from S_PMDS_ASP where UNIT in(select UNIT from B_INVNTORY_UNIT where SEGID='"+segid+"')"
                            +"and INSPECID in (select top 1 INSPECID from S_INSPEACCSE where INSPECID in"
                            +"(select distinct INSPECID from S_PMDS_ASP where "
                            +"UNIT in(select UNIT from B_INVNTORY_UNIT where SEGID='"+segid+"')) order by YEAR_M desc)");
        }
    }
}
